﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OrderAdd.aspx.cs" Inherits="CNVP.JShop.Web.Admin.OrderAdd" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
            <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="IE=7" http-equiv="X-UA-Compatible" />
    <link href="CSS/Edit.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery.js" type="text/javascript"></script>
    <script src="../Scripts/Common.js" type="text/javascript"></script>
    <script type ="text/javascript">
        function KeyUserName() {
            var Url = "CommonWindows/User_CommonWindow.aspx";
            var result = window.showModalDialog(encodeURI(Url), 'example05', 'dialogHeight:400px;dialogLeft:200px;dialogTop:150px;center:yes;help:yes;resizable:yes;status:yes');
            if (result != null) {
                var val = result.split("*");
                var txtUserID = document.getElementById("<% =txtUserID.ClientID %>");
                var txtUserName = document.getElementById("<% =txtUserName.ClientID %>");
                var txtDisCountPercent = document.getElementById("<% =txtDisCountPercent.ClientID %>");
                txtUserID.value = val[0];
                txtUserName.value = val[1];
                txtDisCountPercent.value = val[2];
                var SalePrice = document.getElementsByName("SalePrice");
                var kaoPrice = document.getElementsByName("kaoPrice");
                for (var i = 0; i < kaoPrice.length; i++) {
                    SalePrice[i].value = parseFloat(kaoPrice[i].value) * parseFloat(txtDisCountPercent.value);
                }
                NextInfo();
            }
        }
        function unique(data) {
            data = data || [];
            var a = {};
            for (var i = 0, len = data.length; i < len; i++) {
                var v = data[i];
                if ('undefined' == typeof (a[v])) {
                    a[v] = 1;
                }
            }
            data.length = 0;
            for (var i in a) {
                data[data.length] = i;
            }
            return data;
        }
        function KeyNum() {
            var txtUserID = document.getElementById("<% =txtUserID.ClientID %>");
            var txtUserName = document.getElementById("<% =txtUserName.ClientID %>");
            var inputHotLink = document.getElementById("<% =txtHotLink.ClientID %>").value;
            var inputKey = document.getElementById("<% =txtProKey.ClientID %>").value;
            if (txtUserName.value == "" || txtUserID.value == "") {
                if (confirm("用户名未选择，你需要立即选择用户名吗？")) {
                    KeyUserName();
                }
                else {
                    return false;
                }
            }
            else {
                var Url = "CommonWindows/Product_CommonWindow.aspx?textKey=" + inputKey + "";
                var result = window.showModalDialog(encodeURI(Url), 'example04', 'dialogWidth:650px;dialogHeight:400px;dialogLeft:200px;dialogTop:150px;center:yes;help:yes;resizable:yes;status:yes');
                if (result != null) {
                    var HotLink = document.getElementById("txtHotLink").value;
                    ////////////////////////////////////////////
                    var arrayResult = result.split(",");
                    var arrayHotLink=HotLink.split(",");
                    var myAry = [];
                    for (var i = 0; i < arrayResult.length; i++) {
                        if (!arrayHotLink.contains(arrayResult[i]))//数组交叉集
                            myAry.push(arrayResult[i]);
                    }
                   // alert(myAry);
                    var resultList = "";
                    if (HotLink == "") {
                        resultList = result;
                    }
                    else {
                        if (myAry != "") {
                            resultList = HotLink + "," + myAry;
                        }
                        else {
                            resultList = HotLink;
                        }
                    }
                    document.getElementById("txtHotLink").value = resultList;
                    //alert(myAry);
                    var Prolist = GetAjaxResponse("CommonWindows/AjaxOrderProductList.aspx?UserID=" + txtUserID.value + "&result=" + myAry);
                    $("#AddProductList").append(Prolist);
                    NextInfo();
                }
            }
        }
        function NextInfo() {
            var txtUserID = document.getElementById("<% =txtUserID.ClientID %>");
            var txtUserName = document.getElementById("<% =txtUserName.ClientID %>");
            var txtHotLink = document.getElementById("<% =txtHotLink.ClientID %>");
            if (txtUserName.value == "" || txtUserID.value == "") {
                if (confirm("用户名未选择，你需要立即选择用户名吗？")) {
                    KeyUserName();
                }
                else {
                    return false;
                }
            }
            else {
                var SaleNum = document.getElementsByName("SaleNum");
                var SaleNumArray = "";
                for (var i = 0; i < SaleNum.length; i++) {
                    SaleNumArray += SaleNum[i].value + ",";
                }
                SaleNumArray = SaleNumArray.substring(0, SaleNumArray.length - 1);

                var ShopMustInfo = document.getElementById("ShopMustInfo");
                ShopMustInfo.innerHTML = GetAjaxResponse("CommonWindows/AjaxRefShopMustInfo.aspx?SaleNum=" + SaleNumArray + "&result=" + txtHotLink.value);
                //收货信息确认
                var GetAddressrpList = document.getElementById("GetAddressrpList");
                GetAddressrpList.innerHTML = GetAjaxResponse("CommonWindows/AjaxGetAddressrpList.aspx?UserID=" + txtUserID.value);
                OnLoadGetAddress();
                //订单确认
                //alert(SaleNumArray);
                var OrderCheck = document.getElementById("OrderCheck");
                OrderCheck.innerHTML = GetAjaxResponse("CommonWindows/AjaxOrderTotal.aspx?UserID=" + txtUserID.value + "&SaleNum=" + SaleNumArray + "&result=" + txtHotLink.value);

                $("#GetTrueInfo").css("display", "");
                //注意单选控件
                var rbDeliveryWay = document.getElementsByName("rbDeliveryWay");
                for (var i = 0; i < rbDeliveryWay.length; i++) {
                    rbDeliveryWay[i].checked = false;
                }
            }
            DeliveryFreight();
        }
        function Del(index) {
            if (confirm("你确定要删除吗？")) {
                $("#tr" + index + "").remove();
                var getIdList = "";
                var IDS = document.getElementsByName("IDS");
                for (var i = 0; i < IDS.length; i++) {

                    getIdList += IDS[i].value + ",";
                }
                //alert(getIdList);
                var txtHotLink = document.getElementById("<% =txtHotLink.ClientID %>");
                txtHotLink.value = getIdList.substring(0, getIdList.length - 1);
                NextInfo();
            }
        }
        function DeliveryWayCheck() {
            var $txtHotLink = $("#txtHotLink");
            var $txtProKey = $("#txtProKey");
            var spanSalePriceTatol = document.getElementById("spanSalePriceTatol");
            var inputSalePriceTatol = document.getElementById("inputSalePriceTatol");
            var spanOrderTatol = document.getElementById("spanOrderTatol");
            var inputOrderTatol = document.getElementById("inputOrderTatol");
            var spanDeliveryPrice = document.getElementById("spanDeliveryPrice");
            var inputDeliveryPrice = document.getElementById("inputDeliveryPrice");

            var DeliveryWayPrice = 0;
            var rbDeliveryWayNum = document.getElementById("DeliveryWayPrice"); //配送价
            if (rbDeliveryWayNum != null) {
                var WayNum = rbDeliveryWayNum.value;
                if (WayNum != "") {
                    var arrWayPrice = WayNum.split(":");
                    DeliveryWayPrice = arrWayPrice[1];
                }
            }
            var OrderTatol = 0.00;
            var SalePriceTatol = 0;
            if (inputSalePriceTatol != null) {
                SalePriceTatol = inputSalePriceTatol.value;
            }
            OrderTatol = parseFloat(SalePriceTatol) + parseFloat(DeliveryWayPrice);
            if (spanDeliveryPrice != null && inputDeliveryPrice!=null) {
                spanDeliveryPrice.innerHTML = DeliveryWayPrice;
                inputDeliveryPrice.value = DeliveryWayPrice;
            }
            if (spanOrderTatol != null && inputOrderTatol != null) {
                spanOrderTatol.innerHTML = OrderTatol;
                inputOrderTatol.value = OrderTatol;
            }
        }
        function OrderProductsOnchang(index) {
            var Num = document.getElementById("SaleNum" + index + "").value;//index:产品主ID_详细表ID
            if (Num < 0) {
                document.getElementById("SaleNum" + index + "").value = "1";
            }
            else {
                var NumState = GetAjaxResponse("CommonWindows/AjaxProDetailNum.aspx?IDS=" + index + "&CompareValue=" + Num);
                if (NumState == "0") {
                    alert("库存不足！");
                    document.getElementById("SaleNum" + index + "").value = "1";
                }
            }
            NextInfo();
        }
      </script>
</head>
<body>
    <form id="form1" runat="server" class="registerform" autocomplete="off">
        <div class="Content" >
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="cell">
             <tr>
                <td class="cell_group">
                    <img src="Images/ListIconTitle.jpg" alt="" />&nbsp;您的位置：<a href="OrderList.aspx">订单管理</a> > 添加
                </td>
            </tr>
            </table>
            <h3>
                请选择顾客用户名和订单中商品</h3>
                    <table border="0" cellpadding="0" cellspacing="0"  class="division">
                        <tr >
                            <th>
                                用&nbsp;户&nbsp;名：</th>
                            <td>
                                <asp:TextBox ID="txtUserID" runat="server"  CssClass="Display" />
                                <asp:TextBox ID="txtDisCountPercent" runat="server"  CssClass="Display" />
                                <asp:TextBox ID="txtUserName" runat="server" ReadOnly="True" />
                                <input id="btUserName" type="button" value="选择" onclick="KeyUserName()" />
                                </td>
                        </tr>
                         <tr>
                            <th>
                                选择商品：</th>
                            <td>
                                <asp:TextBox ID="txtHotLink" runat="server" CssClass="Display"  />
                                    关键词：<asp:TextBox ID="txtProKey" runat="server"  />
                                    <input id="btSelectPro" type="button" value="选择" onclick="KeyNum()" />
                                    <br />
                                    <table><tbody id="AddProductList"></tbody></table>
                                </td>
                        </tr>
                    </table>
                    <div id="ShopMustInfo"></div>
                <div  id="GetTrueInfo" style="display:none">
                    <h3>收货信息确认</h3>
                    <div id="GetAddressrpList"></div>
                    <script type="text/javascript">
                        function DeliveryFreight() {
                            var proIDS = "";
                            var proID = document.getElementsByName("proID");
                            for (var i = 0; i < proID.length; i++) {

                                proIDS += proID[i].value + ",";
                            }
                            proIDS = proIDS.substring(0, proIDS.length - 1);
                            ////////////////////////////////////////////////////////////////
                            var SaleNumArray = "";
                            var SaleNum = document.getElementsByName("SaleNum");
                            for (var i = 0; i < SaleNum.length; i++) {
                                SaleNumArray += SaleNum[i].value + ",";
                            }
                            SaleNumArray = SaleNumArray.substring(0, SaleNumArray.length - 1);

                            var result = GetAjaxResponse("../Controls/DeliveryFreight.aspx?SaleNumArray=" + SaleNumArray + "&ProductIDS=" + proIDS + "&ListProvince=" + $("#ListProvince").val() + "");
                            if (result != null) {
                                $("#DeliveryFreight").html(result);
                            }
                            DeliveryWayCheck();
                        }
                        function OnLoadGetAddress() {
                            var GetAddressList = document.getElementById("GetAddressList");
                            GetAddressList.innerHTML = "";
                            $("#GetAddressList").css("display", "none"); //先隐藏
                            var GetAddress_Int = parseInt(document.getElementById("idIsTolerantHidden").value);
                            if (GetAddress_Int > 0) {
                                var rbIsTolerant = document.getElementsByName("rbIsTolerant");
                                for (var i = 0; i < rbIsTolerant.length; i++) {
                                    //alert(rbIsTolerant[i].value);
                                    if (rbIsTolerant[i].checked == true) {
                                        $("#GetAddressList").append(GetAjaxResponse("CommonWindows/AjaxGetAddress.aspx?ID=" + rbIsTolerant[i].value));
                                        ProvinceChange();
                                    }
                                }
                            }
                            else {
                                $("#idIsTolerant2").addClass("Display");
                                IsTolerant2();
                            }
                        }
                        function GetAddressEdit(index) {
                            $("#GetAddressList").css("display", "");
                            $("#rbIsTolerantA" + index + "").attr("checked", "checked");
                            var GetAddressList = document.getElementById("GetAddressList");
                            GetAddressList.innerHTML = "";
                            $("#GetAddressList").append(GetAjaxResponse("CommonWindows/AjaxGetAddress.aspx?ID=" + index));
                            ProvinceChange();

                            //产生需要编辑ID
                            var EditChecked = document.getElementById("EditChecked");
                            EditChecked.innerHTML = "";
                            $("#EditChecked").append("<input id='EditGetAddressID' type='hidden' name='EditGetAddressID' value='" + index + "'>");
                            DeliveryFreight();
                        }
                        function IsTolerant1(index) {
                            $("#GetAddressList").css("display", "none");
                                var GetAddressList = document.getElementById("GetAddressList");
                                GetAddressList.innerHTML = "";
                                $("#GetAddressList").append(GetAjaxResponse("CommonWindows/AjaxGetAddress.aspx?ID=" + index));
                                ProvinceChange();
                                DeliveryFreight();
                        }
                        function IsTolerant2() {
                            $("#GetAddressList").css("display", "");
                            var GetAddressList = document.getElementById("GetAddressList");
                            GetAddressList.innerHTML = "";
                            $("#GetAddressList").append(GetAjaxResponse("CommonWindows/AjaxGetAddress.aspx"));
                            var EditChecked = document.getElementById("EditChecked");
                            EditChecked.innerHTML = "";
                            DeliveryFreight();
                        }
                    </script>
                    <div id="GetAddressList"></div><b id="EditChecked"></b>
                    
                    <h3>配送方式确认</h3>
                    <span id="DeliveryFreight"></span>
                    <h3>支付方式确认</h3>
                    <asp:Label ID="lbPayWay" runat="server"></asp:Label>
                    <!--订单确认-->
                    <div id="OrderCheck"></div>
                    <h3>是否需要发票</h3>
                    <input name="GetInvoice" value="1" type="checkbox" />需要
                    <h3>补充说明</h3>
                    <asp:TextBox ID="txtText" runat="server" TextMode="MultiLine" CssClass="OrderText"  OnClick="clickText('#txtText')" OnBlur="blurText('#txtText')"></asp:TextBox>
                </div>
            <div class="EditBtn">  
            <asp:Button ID="btUp" runat="server" Text="提交" OnClick="btUp_Click" />
            <input type="button" value="取消" onclick="javascript:history.go(-1)" />
            </div>
          </div>
    </form>
    <script type="text/javascript">
        $(function () {
            $("#btUp").click(function () {
                var $txtHotLink = $("#txtHotLink");
                var $txtProKey = $("#txtProKey");
                if ($txtHotLink.val() == "") {
                    alert("请选择商品！");
                    $txtProKey.focus();
                    return false;
                }
                var rbIsTolerantCount = document.getElementsByName("rbIsTolerant");
                if (rbIsTolerantCount.length > 1) {
                    var $rbIsTolerant = $("input[name='rbIsTolerant'][type='radio']:checked");
                    if ($rbIsTolerant.length == 0) {
                        alert("请选择收货信息！");
                        $rbIsTolerant.focus();
                        return false;
                    }
                }
                var $ddlProvince = $("#ListProvince");
                if ($ddlProvince.val() == "") {
                    alert("请选择省区！");
                    $ddlProvince.focus();
                    return false;
                }
                var $ListCity = $("#ListCity");
                if ($ListCity.val() == "") {
                    alert("请选择市区！");
                    $ListCity.focus();
                    return false;
                }
                var $ListArea = $("#ListArea");
                if ($ListArea.val() == "") {
                    alert("请选择地区！");
                    $ListArea.focus();
                    return false;
                }
                var $txtGetAddress = $("#txtGetAddress");
                if ($txtGetAddress.val() == "") {
                    alert("请输入收货地址！");
                    $txtGetAddress.focus();
                    return false;
                }
                var $txtZipCode = $("#txtZipCode");
                if ($txtZipCode.val() != "") {
                    if (!IsPostId($txtZipCode.val())) {
                        alert("邮编格式不正确！");
                        $txtZipCode.focus();
                        return false;
                    }
                }
                var $txtTrueName = $("#txtTrueName");
                if ($txtTrueName.val() == "") {
                    alert("请输入收货人姓名！");
                    $txtTrueName.focus();
                    return false;
                }
                var $txtMobilePhone = $("#txtMobilePhone");
                if ($txtMobilePhone.val() == "") {
                    alert("请输入手机号码！");
                    $txtMobilePhone.focus();
                    return false;
                }
                if (!IsValidMobilePhone($txtMobilePhone.val())) {
                    alert("手机号码格式不正确！");
                    $txtMobilePhone.focus();
                    return false;
                }
                var $txtPhone = $("#txtPhone");
                if ($txtPhone.val() != "") {
                    if (!IsValidPhone($txtPhone.val())) {
                        alert("电话号码格式不正确！");
                        $txtPhone.focus();
                        return false;
                    }
                }
                var $PayWay = $("input[name='PayWay'][type='radio']:checked");
                if ($PayWay.length == 0) {
                    alert("请选择支付方式！");
                    return false;
                }
                return true;
            });
        })
    
    </script>
</body>
</html>
